package com.restaurant.serviceimpl;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.Transactiontype;
import com.restaurant.service.TransactiontypeService;

public class TransactiontypeServiceImpl implements TransactiontypeService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Transactiontype addOrModify( Transactiontype objTransactiontype ) {
       return ( Transactiontype ) hibernateTemplate.merge( objTransactiontype );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Transactiontype deleteRecord( Transactiontype objTransactiontype ) {
       hibernateTemplate.delete( objTransactiontype );
       return objTransactiontype;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Transactiontype modifyRecord( Transactiontype objTransactiontype ) {
       return ( Transactiontype ) hibernateTemplate.merge( objTransactiontype );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Transactiontype> loadAll() {
       return (List<Transactiontype>)hibernateTemplate.findByNamedQuery( "Transactiontype.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Transactiontype loadByPrimaryKey( Long primaryKey ) {
       return (Transactiontype) hibernateTemplate.get( Transactiontype.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Transactiontype deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Transactiontype> loadByHql(String query) {
       return ( List<Transactiontype> ) hibernateTemplate.find( query );
   }
}